import { getQuestionsApi, deleteQuestionsApi, addQuestionsApi, updateQuestionsApi } from '../../api/audit/index'
export const state = () => ({
    list: []
})

export const mutations = {
    SET_LIST(state, data) {
        state.list = data
    },
}

export const actions = {
    // 获取列表
    async getQuestions({ commit }) {
        const r = await getQuestionsApi()
        commit('SET_LIST', r.data)
    },

    // 新增列表
    async addQuestions({ dispatch, commit }, form) {
        const r = await addQuestionsApi({ ...form, uid: 1, answers: form.answers.sort().join(',') })
        console.log(r);
        dispatch('getQuestions')
    },

    // 删除列表
    async deleteQuestions({ dispatch, commit }, id) {
        const r = await deleteQuestionsApi(id)
        dispatch('getQuestions')
    },

    // 修改列表
    async updateQuestions({ dispatch, commit }, form) {
        const r = await updateQuestionsApi({ ...form, uid: 1, answers: form.answers.sort().join(',') })
        dispatch('getQuestions')
    },


}

export const getters = {


}